package com.bwie.lan;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor implements HandlerInterceptor {

	private List<String> includeURLS;
	@Override
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
			Object o) throws Exception {
		// TODO Auto-generated method stub
		String uri = request.getRequestURI();
		System.out.println(uri);
		String object = (String) request.getSession().getAttribute("hehe");
		if(includeURLS.contains(uri)){
			return true;
		}
		else{
			if(object!=null){
				return true;
			}
			else {
				request.getRequestDispatcher("/WEB-INF/view/login.jsp").forward(request, response);
				return false;
			}
		}
		
	}


	/***************/
	public List<String> getIncludeURLS() {
		return includeURLS;
	}

	public void setIncludeURLS(List<String> includeURLS) {
		this.includeURLS = includeURLS;
	}
}
